package com.it;

import com.it.dao.UserDao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class AppForInstanceUser {
    public static void main(String[] args) {
        ////创建实例工厂对象
        //UserDaoFactory userDaoFactory = new UserDaoFactory();
        ////通过实例工厂对象创建对象
        //UserDao userDao = userDaoFactory.getUserDao();
        //userDao.save();

        // 实例化工厂
        // ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        //UserDao userDao = (UserDao) ctx.getBean("userDao");
        //userDao.save();

        // 测试bean作用范围: 单例/非单例
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserDao userDao1 = (UserDao) ctx.getBean("userDao");
        UserDao userDao2 = (UserDao) ctx.getBean("userDao");
        System.out.println(userDao1);
        // => com.it.dao.impl.UserDaoImpl@544fa968
        System.out.println(userDao2);
        // => com.it.dao.impl.UserDaoImpl@544fa968
    }
}
